<?php

use app\assets\TableAsset;
use app\widgets\ManagerTableOp;
use yii\helpers\Html;
use yii\helpers\Url;

/**
 * @var $this yii\web\View
 * @var $packageList app\models\Package[]
 */

TableAsset::register($this);

$this->title = '物联网卡类型';
$this->params['breadcrumbs'][] = '物联网卡管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('?', 'get', ['class'=>'form-inline']);?>
<div class="form-group">
    <a href="<?php echo Url::to(['/admin/card/cardtype-edit']);?>" class="btn btn-success btn-sm">添加</a>
</div>
<?php echo Html::endForm();?>
<table class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th class="center">
                <label class="pos-rel">
                    <input type="checkbox" class="ace" />
                    <span class="lbl"></span>
                </label>
            </th>
            <th class="center">名称</th>
            <th class="center">操作</th>
        </tr>
    </thead>

    <tbody>
        <?php foreach ($cardType as $type) {?>
            <tr>
                <td class="center"><label class="pos-rel"><input type="checkbox" class="ace" value="<?php echo $type->id;?>" /><span class="lbl"><?php echo $type->id;?></span></label></td>
                <td class="center"><?php echo Html::encode($type->name);?></td>
                <td class="center"><?php echo ManagerTableOp::widget(['items' => [
                        ['icon' => 'fa fa-pencil', 'href' => Url::to(['/admin/card/cardtype-edit', 'id' => $type->id]), 'btn_class' => 'btn btn-xs btn-success', 'tip' => '修改', 'color' => 'green'],
                        ['icon' => 'fa fa-trash', 'onclick' => 'deleteLog('.$type->id.')', 'btn_class' => 'btn btn-xs btn-danger','tip' => '删除', 'color'=>'red']
                    ]]);?></td>
            </tr>
        <?php }?>
    </tbody>
</table>
<script type="text/javascript">
    function deleteLog(id) {
        if (!confirm('确定要删除此卡类型吗？')) {
            return false;
        }
        $.getJSON('<?php echo Url::to(['/admin/card/cardtype-del']);?>', {'id':id}, function(json) {
            if (callback(json)) {
                $('#data_' + id).remove();
            }
        });
    }
</script>
